﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace FishSimulation.Converters {
    [ValueConversion(typeof(string), typeof(System.Windows.Media.ImageSource))]
    public class Base64StringToImageSourceConverter : IValueConverter {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
            if (value != null && value is string) {
                System.Drawing.Image i = Utils.Base64ToImage(value.ToString());                
                if (i != null) {
                    return Utils.ImageToMediaImage(i);
                }
            }
            return Binding.DoNothing;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
            return Binding.DoNothing;
        }
    }
}
